<%--
  Copyright (c) 2006, Mark Allen. All rights reserved.
  
  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:
  
  Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.
  
  Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.
  
  Neither the name of Planet Achewood nor the names of its contributors may be
  used to endorse or promote products derived from this software without
  specific prior written permission.
  
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  POSSIBILITY OF SUCH DAMAGE.

  @author Mark Allen [mark.a.allen@gmail.com]
  @since Nov 19, 2006: $Revision: 127 $ $Date: 2006-12-23 23:45:09 +0000 (Sat, 23 Dec 2006) $
--%>

<%@ include file="/WEB-INF/jsp/taglibs.jsp"%>

<script type="text/javascript">
// <![CDATA[
function onLoad() {
	$("username").focus();
}

function signIn() {
	var username = DWRUtil.getValue("username");
	var password = DWRUtil.getValue("password");	
	alert("signin");
}

function signUp() {
	var signUpFormData = {};
	signUpFormData["username"] = DWRUtil.getValue("sign-up-username");
	signUpFormData["password"] = DWRUtil.getValue("sign-up-password");
	signUpFormData["passwordAgain"] = DWRUtil.getValue("sign-up-password-again");
	signUpFormData["email"] = DWRUtil.getValue("sign-up-email");
	
	DwrUserService.signUp(signUpFormData, {
		callback:function(user) {
			alert("signed up...");
		},
		errorHandler:function(message, exception) {
			removeAllChildren("errorList");
			for(var error in exception.errors) {
				var errorLi = document.createElement("li");
				errorLi.appendChild(document.createTextNode(exception.errors[error]));
				$("errorList").appendChild(errorLi);
			}
			Element.show("errors");
		}
	});
}

function displaySignUp() {
	Element.hide("sign-in");
	Element.show("sign-up");
	$("sign-up-username").focus();	
}

function cancelSignUp() {
	Element.hide("sign-up");
	Element.show("sign-in");
	$("username").focus();	
}
// ]]>
</script>

<div id="sign-in" class="sign-in">

<!--<h2 style="margin-bottom: 5px;" class="centered boxed">Sign In</h2>-->

<form action="javascript://" class="centered">

<table style="margin: auto;">
<tbody>
<tr>
	<td class="left-aligned">Username:</td>
	<td class="left-aligned"><input type="text" id="username" size="15" tabindex="1" /></td>
</tr>
<tr>
	<td class="left-aligned">Password:</td>
	<td class="left-aligned"><input type="password" id="password" size="15" tabindex="2" /></td>
</tr>
<tr>
	<td class="left-aligned"><input type="submit" value="Sign In" tabindex="3" onclick="signIn();" /></td>
	<td class="right-aligned"><a href="javascript://" onclick="displaySignUp();">...or sign up</a></td>
</tr>
</tbody>
</table>

</form>

</div>

<div id="sign-up" class="sign-up" style="display: none;">


<h2 class="centered boxed">Sign Up <span id="why-sign-up-link">[<a href="javascript://" onclick="Element.hide('why-sign-up-link'); Element.show('why-sign-up');">why?</a>]</span></h2>

<form action="javascript://" class="left-aligned" style="margin-bottom: 10px; margin-top: 10px;">
<table style="margin: auto;" cellspacing="3">
<tbody>
<tr>
	<td class="right-aligned">Username:</td>
	<td class="left-aligned"><input type="text" id="sign-up-username" size="15" tabindex="4" /></td>
</tr>
<tr>
	<td class="right-aligned">Password:</td>
	<td class="left-aligned"><input type="password" id="sign-up-password" size="15" tabindex="5" /></td>
</tr>
<tr>
	<td class="right-aligned">Password [again]:</td>
	<td class="left-aligned"><input type="password" id="sign-up-password-again" size="15" tabindex="6" /></td>
</tr>
<tr>
	<td class="right-aligned">Email Address [optional]:</td>
	<td class="left-aligned"><input type="text" id="sign-up-email" size="20" tabindex="7" /></td>
</tr>
<tr>
	<td class="right-aligned"><input type="button" value="Cancel" tabindex="8" onclick="cancelSignUp();" /></td>
	<td class="left-aligned"><input type="submit" value="Sign Up" tabindex="9" onclick="signUp();" /></td>
</tr>
</tbody>
</table>
</form>

<div id="errors" style="display: none;">
<p id="error-message" style="color: red;">You must fix the following before you can sign up:</p>
<ul id="errorList"></ul>
</div>

<div id="why-sign-up" style="display: none;">
<h2 class="centered boxed">Why Sign Up?</h2>
<p class="justified">As a Planet Achewood user, your strip comments and ratings are associated with you.
Others can see what you like and what you don't.  We'll have more for registered users later, like email notifications when new 
strips have been posted, the ability to mark strips as "favorites", and so on.
</p>
</div>

</div>